# class Animal:
#     def call(self):
#         print('动物叫')
# class Dog(Animal):
#     def call(self):
#         print('旺旺')
# class Cat(Animal):
#     def call(self):
#         print('喵喵')
# class Person(Animal):
#     def call(self):
#         print('你过来啊')
#     pass
# dog = Dog()
# cat = Cat()
# dog.call()
# def do_call(obj):
#     print('前面添加1')
#     obj.call()
#     print('后面添加2')
#
#
# # 其他语言
# # def do_call(obj Animal):
# #     obj.call()
#
# do_call(Dog())
# do_call(Cat())
# do_call(Person())
# 魔术方法 new
class Person:
    def __new__(cls, *args, **kwargs):
        return super().__new__(cls, *args, **kwargs)
p1 = Person()
print(p1)
class SINGleton:
    __instance = None
    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            cls.__instance = super().__new__(cls, *args, **kwargs)
        return cls.__instance
s1 = SINGleton()
s2 = SINGleton()
print(s1)
print(s2)
# 1 / 0
'''
trg可能发生异常的代码
except异常的类型:
捕获到异常的代码'''
# #TODO
# try:
#     1/0
# except ZeroDivisionError:
#     print('0不能作为除数使用')
# #TODO
# try:
#     1 /0
# except NameError:
# #     print('0不能作为除数使用')
# try:
#     num = int(input('请输入一个数字:'))
#     num1 = 1 / num
# except (ZeroDivisionError,  ValueError):
#     print('你输入的数字不合法')
# try:
#     num1 = int(input('请输入一个数字:'))
#     num2 = 1 / num1
# except ZeroDivisionError:
#     print('输入的数字不能是0')
# except ValueError:
# #     print('输入的数字不合法')
# try:
#     num1 = int(input('数字:'))
#     result = 1 / num1
# except ZeroDivisionError as e:
#     print(e)
#捕获单个异常
# try:
#     num2 = int(input('数字:'))
#     result = 1 / num2
# except (ZeroDivisionError, ValueError, NameError) as e :
# #     print(e)
#
# try:
#     num = int(input('数字:'))
#     result = 1 / num
# except Exception :
#     print('数据不合法')
# try :
#     num = int(input('数字:'))
#     result = 1 / num
#     print(name)
# except:
#     print('代码有错误')
# else 代码没有错误执行的代码
# try :
#     num = int(input('数字:'))
#     result = 1 / num
# except (ValueError, ZeroDivisionError):
#     print('数据不合法')
# else:
#     print('输入的数据没有问题')
# # 异常的finally-语法
# try:
#     result = 1 / int(input('sun:'))
# except ZeroDivisionError:
#     print('数据不合法')
# else:
#     print('输入的数据没有问题')
# finally:
#     print('都执行')
# def fn1():
#     1/ 0
# def fn2():
#     fn1()
# def fn3():
#     try:
#         fn2()
#     except ZeroDivisionError:
#         print('0不能是除数')
# fn3()
# try:
#     try:
#         try:
#             result = 1 / int(input('num:'))
#         except ZeroDivisionError:
#             print('输入的数字不能是0')
#
#     except NameError:
#         print('name')
# except ValueError:
#     print('传入')
# 自定义异常类
class LenError(Exception):
    def __str__(self):
        # 　异常描述信息
        return '长度不合法'


# 　语法:while for in def rte break inselt append extend pop range true fa
# 抛出异常
# raise 类名()
#
# username = input('username:')
# try:
#     if (len(username) >= 6) and (len(username) <= 18):
#         print('用户名合法')
#     else:
#         raise LenError()
# except LenError as e:
#     print(e)


